﻿package core.ui.controls
{
    import core.event.*;
    import flash.display.*;
    import flash.events.*;

    public class Checkbox extends Sprite
    {
        public var checked:Boolean = false;
        private var title:Literal;
        private var uc:IconButton;
        private var ck:IconButton;

        public function Checkbox(param1:String = "")
        {
            this.uc = new IconButton(null, "", new CheckboxUncheckedHover());
            this.ck = new IconButton(null, "", new CheckboxCheckedHover());
            this.ck.y = 1;
            this.uc.y = 3;
            this.ck.visible = false;
            addChild(this.uc);
            addChild(this.ck);
            if (param1 != "")
            {
                this.title = new Literal(param1);
                this.title.x = 14;
                this.title.y = -1;
                addChild(this.title);
            }
            this.addEventListener(MouseEvent.MOUSE_DOWN, this.MouseDown, false, 1, true);
            return;
        }// end function

        private function MouseDown(event:MouseEvent) : void
        {
            this.checked = Boolean(!this.checked);
            this.uc.visible = !this.checked;
            this.ck.visible = this.checked;
            event.stopPropagation();
            dispatchEvent(new ChangeEvent(this.checked));
            return;
        }// end function

        public function Check(core.ui.controls:Checkbox/Checkbox:Boolean = true) : void
        {
            this.checked = core.ui.controls:Checkbox/Checkbox;
            this.uc.visible = !this.checked;
            this.ck.visible = this.checked;
            return;
        }// end function

    }
}
